<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const data = [
            {
                入职日期: 44505,
                姓名: "小张",
                工号: "9002",
                手机号: "13800000252",
                转正日期: 44892,
                部门: "总裁办"
            },
            {
                入职日期: 44506,
                姓名: "小李",
                工号: 9006,
                手机号: "13810000512",
                转正日期: 44893,
                部门: "总裁办",
            }

        ]
        // 需求: 我们上传excel之后(xlsx插件会给我们一个数组对象)
        // result = [
        // {
        //     timeOfEntry:44505,
        //     mobile: "13800000252",
        //     username:"小张",
        //     correctionTime:  44892,
        //     workNumber: "9002",
        //     departmentName:"总裁办"
        // }
        // ]
        function transfromZhCNToEn(arr) {
            // 翻译映射表
            const mapInfo = {
                入职日期: 'timeOfEntry',
                手机号: 'mobile',
                姓名: 'username',
                转正日期: 'correctionTime',
                工号: 'workNumber',
                部门: 'departmentName',
                聘用形式: 'formOfEmployment'
            }
            //   const newArr=[]
            return arr.map(item => {
                const obj = {}
                const keyList = Object.keys(item)
                // console.log(keyList);
                keyList.map(childItem => {
                    const enKey = mapInfo[childItem]
                    // 当key值是日期的时候我们需要单独处理
                    if(enKey === 'timeOfEntry' || enKey === 'correctionTime'){
                    obj[enKey] = formatExcelDate(item[childItem])       
                    }else {
                    obj[enKey] = item[childItem]

                    }
                })
                // console.log(obj);
                return obj
                //   newArr.push(obj)
            });
        }
        function formatExcelDate(numb, format = '-') {
            const time = new Date((numb - 25567) * 24 * 3600000 - 5 * 60 * 1000 - 43 * 1000 - 24 * 3600000 - 8 * 3600000)
            time.setYear(time.getFullYear())
            const year = time.getFullYear() + ''
            const month = time.getMonth() + 1 + ''
            const date = time.getDate() + ''
            if (format && format.length === 1) {
                return year + format + month + format + date
            }
            return year + format + (month < 10 ? '0' + month : month) + format + (date < 10 ? '0' + date : date)
        }
        transfromZhCNToEn(data)

    </script>
</body>

</html>